home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 726-750 / 742 / icalc / s / init.readme < prev    next >
Text File  |  1995-03-18  |  4KB  |  133 lines

  1. # This is a fully commented version of the icalc.init file that should
  2. # be installed in your S: directory. It is intended to provide hints and
  3. # tips for new users.
  4. #
  5. # This file is readable by icalc, and has the same effect at the normal
  6. # icalc.init file.
  7. #
  8. # ----------------------------------------------------------------------------
  9. #
  10. # Standard startup-file for icalc.
  11. # Updated for version 2.1. Also, you may want to include other scripts
  12. # (such as gamma.ic) by read command.
  13. #
  14. # MWS, July 1992.
  15.  
  16. # switch off confirmation of function definitions
  17. silent
  18.  
  19. #
  20. # If icalc is called from the Workbench, only the default command paths
  21. # are given. We can add paths using an exec command to call the CLI Path
  22. # command, e.g.
  23. #
  24. # exec "path bin: add"
  25. #
  26. # We could also run an editor in the backgroung on startup, e.g.
  27. #
  28. # exec "run memacs"
  29. #
  30.  
  31. #
  32. # Default number base used for displaying numbers is decimal. We could
  33. # change that here with a call to outbase(newbase).
  34. #
  35. # Default number of significant digits displayed is 12. Use the builtin
  36. # prec(numsigdigits) to change this.
  37. #
  38.  
  39.  
  40. # function informing you how long icalc session has been running in seconds.
  41. # time(0) returns the system time in seconds. We use an underscore to start
  42. # the variable name as a convention indicating an internal purpose.
  43. _sessionstart = time(0)
  44.  
  45. # restore ans to zero
  46. # the time call above set the ans 'constant' - let's restore it to zero
  47. 0
  48.  
  49. # time(x) returns the system time less x. We set the time we started above,
  50. # so this declares a function telling us how long icalc has been running.
  51. func session() = time(_sessionstart)
  52.  
  53. # simple stopwatch functions
  54. # along same lines as session() above
  55. func start() = (_start = time(0))
  56. func stop() = time(_start)
  57.  
  58. # timer of evaluation
  59. # Use as e.g. timer(Sum(n=1,1000,1/sqr(n)))
  60. # Prints the result of its expression, and time it took to
  61. # evaluate the expression in seconds.
  62. func timer(~expr) = { local t; t = time(0); print(expr); time(t); }
  63.  
  64. # A few simple time-savers
  65. # Examples of the simplest function definitions
  66. func deg(z) = DEG*z        # convert radians to degrees
  67. func rad(z) = z/DEG        # and degrees to radians
  68. func log(z) = ln(z)/LOG10    # base-10 logarithm
  69. func lg(z) = ln(z)/LOG2        # base-2 logarithm
  70. func logn(z,n) = ln(z)/ln(n)    # base-n logarithm
  71.                 # (works with complex bases too:)
  72.  
  73. # Switch bases - note adjustment of significant figures
  74. # Each of these functions calls another 2, using a simple 'block'
  75. func bin() = { outbase(2); prec(35); }    # display results in binary
  76. func oct() = { outbase(8); prec(15); }    # display results in ocal
  77. func dec() = { outbase(10); prec(12); }    # display results in decimal
  78. func hex() = { outbase(16); prec(10); }    # display results in hex
  79.  
  80. # Inverse hyperbolic trig functions
  81. # These are standard formulas simply translated into icalc functions
  82. func asinh(z) = -i*asin(i*z)
  83. func acosh(z) = -i*acos(z)
  84. func atanh(z) = i*atan(-i*z)
  85.  
  86. # Combinatorics - could be replaced with defs in gamma.ic
  87. # Simple use of special function Prod(). Note that _n is used.
  88. func fact(n) = Prod(_n=1,n,_n)
  89. func perm(n,r) = Prod(_n=n-r+1,n,_n)
  90. func comb(n,r) = perm(n,r)/fact(r)    # defined in terms of
  91.                     # other user functions
  92.  
  93. # miscellaneous
  94.  
  95. # Fractional part of a number
  96. # floor() strips imaginary part and rounds real part down to an integer.
  97. func frac(z) = Re(z - floor(z))
  98.  
  99. # Round real & imag parts
  100. # Shift number up, take nearest integer, shift it back down
  101. func round(z,places) = int(z*10^places)/10^places
  102.  
  103. # Create complex number from modulus and argument
  104. func polar(r,theta) = r*exp(i*theta)
  105.  
  106. # Create complex number from real and imaginary parts
  107. func complex(real,imag) = real + i*imag
  108.  
  109. # Convert decimal hours to hours, mins, seconds
  110. # Using print() to generate three answers; the last expression in the
  111. # block is returned and printed when the function is called, so no need
  112. # for a further print() call.
  113. func hms(h) = { print(floor(h)); print(floor(_t = frac(h)*60)); frac(_t)*60; }
  114.  
  115. # Convert hours, mins, seconds to decimal hours
  116. # This is the 'inverse' of hms() defined above.
  117. func hours(h,m,s) = h+m/60+s/3600
  118.  
  119. # restore display of results, messages
  120. verbose
  121.  
  122. #
  123. # ----------------------------------------------------------------------------
  124. #
  125.  
  126. # If we had any other favourite functions we wished defined, we could
  127. # either declare them here or in a file called (say) S:icalc.user, and
  128. # then use the commands
  129. #
  130. # echo "Reading user-definitions file"
  131. # read "s:icalc.user"
  132. #
  133.